package com.aerfafish.spider.neo4j.spider.service.impl;

import com.aerfafish.spider.neo4j.dao.Company;
import com.aerfafish.spider.neo4j.repository.CompanyRepository;
import com.aerfafish.spider.neo4j.spider.service.CompanyService;
import org.neo4j.driver.exceptions.TransientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.stereotype.Service;

/**
 * @author aerfafish
 * @date 2021/4/23 10:28 上午
 */
@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    CompanyRepository companyRepository;

    @Override
    public void save(Company company) throws Exception {
        save(company.getCode());
    }

    @Override
    public void save(String code) throws Exception {
        if (code == null) {
            throw new Exception("code is null");
        }
        try {
            companyRepository.save(code);
        } catch (TransientException | InvalidDataAccessApiUsageException e) {
            try {
                companyRepository.save(code);
            } catch (TransientException | InvalidDataAccessApiUsageException e0) {
                companyRepository.save(code);
            }
        }

    }
}
